<template>
  <div class="login_color">
      <div class="login_box">

          <el-form ref="loginFormRef" class="login_form" :model="loginForm" :rules="loginFormRules">
              <!-- 用户名 -->
              <el-form-item prop="name">
                  <el-input v-model="loginForm.name"  prefix-icon="el-icon-user-solid"></el-input>
              </el-form-item>
                 <!-- 密码 -->
                <el-form-item prop="password">
                  <el-input  v-model="loginForm.password" prefix-icon="el-icon-s-goods" ></el-input>
              </el-form-item>
                 <!-- 按钮 -->
               <el-form-item class="but">
                  <el-button type="primary" @click="login">登录</el-button>
                  <el-button type="info" >重置</el-button>
              </el-form-item>
          </el-form>
      </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      loginForm: {
        name: 'admin',
        password: '123456'
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入登录名称', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async login () {
      const { data: res } = await this.$http.post('login', this.loginForm)
      console.log(res)
      if (res.msg !== 200) {
        alert('登录失败')
      } else {
        alert('登录成功')
      }
    },
    reset () {

    }
  }
}
</script>

<style lang="less" scoped>
  .login_color{
      background-color: rgb(41, 66, 99);
      height: 100%;
  }
  .login_box{
      width: 520px;
      height: 340px;
      background-color: aliceblue;
      border-radius: 10px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%,-50%);
  }
  .but{
      display: flex;
      justify-content: flex-end;
  }

  .login_form{
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box;
  }
</style>
